<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="bbs.*,core.*,util.*" %>
<%@ page import="java.util.*" %>
<%@ include file="/WEB-INF/include/checkUser.jsp" %>
<%
    RequestParameter param = new RequestParameter(request);
    int bid = param.getInt("bid", 0);
    int aid = param.getInt("aid", 0);
    String cmd = param.getString("cmd", "");

    Article article = ArticleDAO.selectById(aid);
    BoardService boardService = new BoardService(request, bid);

    if (cmd.equals("delete")) {
        if (boardService.canDeleteArticle(article)) {
            ArticleDAO.deleteById(aid);
        } else throw new UnauthorizedAccessException("게시글 삭제 권한 없음");
    } else if (cmd.equals("notice")) {
        if (boardService.canManageBoard()) {
            article.setNotice(!article.isNotice());
            ArticleDAO.update(article);
        } else throw new UnauthorizedAccessException("게시글 관리 권한 없음");
    }
    String targetUrl = "articleList.jsp?" +
            request.getQueryString().replaceAll("&?aid=[0-9]+","").replaceAll("&?cmd=[a-z]+", "");
    response.sendRedirect(targetUrl);
%>
